<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <h2>修改密码</h2>
        </div>
      </el-col>
    </el-row>


    <el-row>
      <el-col :span="5" class="labClass">
        <div class="grid-content bg-purple">
          <span>旧密码:</span>
        </div>
      </el-col>
      <el-col :span="16">
        <div class="grid-content bg-purple-light">
          <el-input v-model="userpwd" placeholder="旧密码"></el-input>
        </div>
      </el-col>
      <el-col :span="3" class="labClass">
      </el-col>
    </el-row>

    <p/>
    <el-row>
      <el-col :span="5" class="labClass">
        <div class="grid-content bg-purple">
          <span>新密码:</span>
        </div>
      </el-col>
      <el-col :span="16">
        <div class="grid-content bg-purple-light">
          <el-input v-model="userNewPwd" type="password" placeholder="新密码"></el-input>
        </div>
      </el-col>
      <el-col :span="3" class="labClass">
      </el-col>
    </el-row>
    <p/>

    <p/>
    <el-row>
      <el-col :span="5" class="labClass">
        <div class="grid-content bg-purple">
          <span>确认新密码:</span>
        </div>
      </el-col>
      <el-col :span="16">
        <div class="grid-content bg-purple-light">
          <el-input v-model="userNewPwdOk" type="password" placeholder="确认新密码"></el-input>
        </div>
      </el-col>
      <el-col :span="3" class="labClass">
      </el-col>
    </el-row>
    <p/>


    <el-button type="success" @click="update">修改</el-button>


  </div>
</template>

<script>
export default {
  name: "updatePwd",
  data() {
    return {
      userpwd: '',
      userNewPwd: '',
      userNewPwdOk: ''
    }
  },
  methods: {
    update() {
      let loginUser = sessionStorage.getItem("loginUser")
      if (sessionStorage.getItem("loginUser") != null) {
        let userId=JSON.parse(loginUser).userId;
        let userPwd=JSON.parse(loginUser).userPwd;
        if (this.userNewPwd == this.userNewPwdOk && this.userpwd==userPwd) {
          let formData = new FormData()
          formData.append("userId", userId)
          formData.append("userPwd", this.userNewPwd)
          this.$axios.post('drp/user/updateUserPwd', formData).then(
              r => {
                console.log(r.data)
                if (r.data == 'ok') {
                  location.href = "/index"
                }
              }
          )
        } else {
          this.$message.error('3次密码输入有问题')
        }
      } else {
        this.$message.error('请先登录')
      }
    }
  }
}
</script>

<style scoped>

</style>